package com.yunxin.admin.system.api.download;

import com.fasterxml.jackson.core.type.TypeReference;
import com.yunxin.admin.system.api.download.extenal.DownloadFileCommand;
import com.yunxin.common.utils.OkHttpUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author zero°
 * @since 2023-06-17
 */
@Component
public class DownloadFileHandle {

    @Value("${download.server.url}")
    private String downloadServerUrl;

    private static final String SYSTEM_CODE = "yunxin-boke";

    @Async("asyncDownloadFileThreadPool")
    public void downloadFileAsync(DownloadFileCommand command) {
        command.setSystemCode(SYSTEM_CODE);
        OkHttpUtils.X.post(downloadServerUrl + "/download/downloadFile", command, new TypeReference<>() {
        });
    }

    @Async("asyncDownloadFileThreadPool")
    public void downloadWorldFileAsync(DownloadFileCommand command) {
        command.setSystemCode(SYSTEM_CODE);
        OkHttpUtils.X.post(downloadServerUrl + "/download/downloadWorldFile", command, new TypeReference<>() {
        });
    }
}
